#ifndef AUDIOOUTPUT_H
#define AUDIOOUTPUT_H

#include <math.h>
#include <stdio.h>
#include <QObject>
#include <QMainWindow>
#include <QIODevice>
#include <QTimer>
#include <QPushButton>
#include <QLabel>
#include <QComboBox>
#include <QByteArray>
#include <QSlider>
#include <QSpinBox>
#include <QAudioOutput>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDial>
#include "generator.h"
#include <QList>
#include <QLCDNumber>
#include <QLabel>
#include "GUI.h"


class AudioTest : public QMainWindow
{
    Q_OBJECT
public:
    int ToneFrequencyHz;
    QSlider* slider;
    QSpinBox* slider_value;
    QHBoxLayout* Hbox;
    QHBoxLayout* Hbox_buttons;
    QHBoxLayout* VolControl;
    QLabel* comboLabel;

    AudioTest();
    ~AudioTest();


private:
    void initializeWindow();
    void initializeAudio();
    void createAudioOutput();

private:
    QTimer*          m_pullTimer;

    // Owned by layout
    QPushButton* startstopbutton;
    QComboBox*       m_deviceBox;

    QAudioDeviceInfo m_device;
    Generator*       m_generator;
    QAudioOutput*    m_audioOutput;

// Volume stuff
    QLabel* VolLabel;
    QPushButton* IncreaseVolume;
    QPushButton* DecreaseVolume;
    QLCDNumber*  LCDVol;
    QVBoxLayout* VLayout;
    QDial* volume_dial;
    QDial* volume_db_dial;



    QIODevice*       m_output; // not owned
    QAudioFormat     m_format;

    bool             m_pullMode;
    QByteArray       m_buffer;

    static const QString PushModeLabel;
    static const QString PullModeLabel;
    static const QString SuspendLabel;
    static const QString ResumeLabel;

private slots:
    void notified();
    void pullTimerExpired();
    void deviceChanged(int index);
    void update_frequency();
    void start_stop_sound();
    void increase_vol(void);
    void decrease_vol(void);
    void change_vol(int i);
};

#endif
